package com.rpp.study.feign;

import com.rpp.study.base.LagouResponse;
import com.rpp.study.hystrix.HystrixUserFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @Description
 * @Author rpp
 * @Date 2020/8/28 10:35 下午
 */
@FeignClient(value = "service-user", path = "/api/user", fallbackFactory = HystrixUserFactory.class)
public interface FeignUser {

    /**
     * 注册接⼝口，true成功，false失败
     *
     * @param email
     * @param password
     * @param code
     * @return
     */
    @PostMapping(value = "/register/{email}/{password}/{code}", consumes = MediaType.APPLICATION_JSON_VALUE)
    LagouResponse<Boolean> register(@PathVariable("email") String email,
                                    @PathVariable("password") String password,
                                    @PathVariable("code") String code);

    /**
     * 是否已注册，根据邮箱判断,true代表已经注册过， false代表尚未注册
     *
     * @param email
     * @return
     */
    @GetMapping(value = "/isRegistered/{email}")
    LagouResponse<Boolean> isRegistered(@PathVariable("email") String email);

    /**
     * 登录接⼝口，验证⽤用户名密码合法性，根据⽤用户名和 密码⽣生成token，token存⼊入数据库，并写⼊入cookie 中
     * 登录成功返回邮箱地址，重定向到欢迎⻚页
     *
     * @param email
     * @param password
     * @return
     */
    @PostMapping(value = "/login/{email}/{password}", consumes = MediaType.APPLICATION_JSON_VALUE)
    LagouResponse<String> login(@PathVariable("email") String email,
                                @PathVariable("password") String password);

    /**
     * 根据token查询⽤用户登录邮箱接⼝口
     *
     * @param token
     * @return
     */
    @GetMapping(value = "/info/{token}")
    LagouResponse<String> info(@PathVariable("token") String token);
}
